package com.lxyk.yygh.order.listener;

import com.lxyk.yygh.common.rabbit.constant.MqConst;
import com.lxyk.yygh.model.order.OrderInfo;
import com.lxyk.yygh.order.service.OrderService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;

//延时队列实现订单取消
@Component
public class DelayConsumerListener {

    @Autowired
    private OrderService orderService;


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MqConst.DELAY_QUEUE_NAME, durable = "true"),
            exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_DELAY),
            key = {MqConst.ROUTING_DELAY}
    ))
    public void receiveOrderMessage(OrderInfo orderInfo, Message message, Channel channel){
        //取消订单
        orderService.cancelOrder(orderInfo.getId());
    }



}
